<template>
  <view class="activity">
    <!-- <swiper class="swiper" :indicator-dots="indicatorDots" :loop="true" :autoplay="autoplay" :interval="interval" :duration="duration">
        <swiper-item>
            <view class="swiper-item uni-bg">
                <image :src="cartoonList[3]" mode="widthFix"></image>
            </view>
        </swiper-item>
        <swiper-item>
            <view class="swiper-item uni-bg">
                <image :src="cartoonList[6]" mode="widthFix"></image>
            </view>
        </swiper-item>
        <swiper-item>
            <view class="swiper-item uni-bg">
                <image :src="cartoonList[7]" mode="widthFix"></image>
            </view>
        </swiper-item>
    </swiper> -->
    <view class="text">~小明同学邀请你一起参加活动啦~</view>
    <view v-for="(item, index) in activityList" :key="index">
      <uni-card
        :title="item.name"
        mode="style"
        :is-shadow="true"
        :thumbnail="item.photo"
        :extra="item.createTime"
        :note="item.description"
        @click="handleClick(item)"
      >
        {{item.content}}
      </uni-card>
    </view>
  </view>
</template>

<script>
import {uniCard} from '@dcloudio/uni-ui'
import {getActivity} from '../../../api/activity'
import {getCartoonPic} from '@/api/food'
export default {
  name: 'home-activity',
  components: {
    uniCard
  },
  data() {
    return {
      indicatorDots: true,
      autoplay: true,
      interval: 2000,
      duration: 500,
      activityList: [],
      pageQuery: {
        pageNum: 1,
        pageSize: 2
      },
      cartoonList: []
    }
  },
  mounted() {
    this.getActivity()
    // this.getCartoonPic()
  },
  methods: {
    getActivity() {
      const data = {
        pageNum: this.pageQuery.pageNum,
        pageSize: this.pageQuery.pageSize
      }
      getActivity(data).then(res => {
        if(res.code !== 200) {
          uni.showToast({
            title: res.message,
            icon: 'none'
          })
        }
        console.log(res.data)
        this.activityList = res.data.list
      })
    },
    getCartoonPic() {
		getCartoonPic().then(res => {
			if (res.code !== 200) {
				return uni.showToast({
						title: res.message,
						icon: 'none'
				})
			}
			this.cartoonList = res.data
		})
    },
    handleClick(item) {
      if(item.name === '招募校园大使') {
        // 跳转到报名页面
        uni.navigateTo({
           url: `/pages/signup/signup-activity?activityId=${item.id}`
        })
      }else if (item.name === '光盘行动') {
        uni.navigateTo({
           url: '/pages/mine/myDiskTable'
        });
      }
    }
  },
}
</script>

<style lang='scss'>
  .activity {
    swiper {
      height: 230px;
    }
    swiper-item {
      height: 250px;
    }
    .uni-bg {
      height: 100%;
      background-color: $theme-color;
    }
    .text {
      margin: 20px auto;
      display: flex;
      justify-content: center;
      color: $theme-color;
      font-size: 16px;
      font-weight: bold;
    }
    .activity {
        margin: 10px;
        padding: 20px;
        // width: 100%;
        border-top: 1px $theme-color solid;
        border-bottom: 1px $theme-color solid;
        .activity-text {
            margin-bottom: 10px;
            display: block;
            color: #333;
            font-size: 16px;
        }
    }
  }
</style>